import '../entity_factory.dart';

class HttpResult<T> {
  static const HTTP_STATUS_DEFAULT = -9999;
  static const HTTP_STATUS_OK = 0;

  int code = HTTP_STATUS_DEFAULT;
  String message;
  T data;

  ///
  /// 简单的json直接转换成对象
  ///
  HttpResult.parseData(Map<String, dynamic> json) {
    code = int.parse(json['code'].toString());
    message = json['message'];

    ///
    /// 如果传递的为dynamic直接返回数据
    ///
    if (T.toString() == "dynamic" || T.toString() =="String") {
      data = json["data"];
    } else {
      ///
      /// 其他简单类型进行json解析
      ///
      Map<String, dynamic> dataMap = json["data"];
      if (dataMap != null) {
        data = EntityFactory.generateOBJ(dataMap);
      }
    }
  }

  bool isDataEmpty() {
    if (data == null) {
      return true;
    }

    return false;
  }
}
